package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    NursingLevelMapper nursingLevelMapper;
    @Override
    public List<NursingPlanVo> queryAll() {
        List<NursingPlanVo> nursingPlanVoList=nursingLevelMapper.queryAll();
        return nursingPlanVoList;
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.add(bean);
    }

    @Override
    public PageResponse<NursingLevelVo> listByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevel> nursingLevelPage =nursingLevelMapper.listByPage(name,pageNum,pageSize,status);
        PageResponse<NursingLevelVo> nursingLevelVoPageResponse = PageResponse.of(nursingLevelPage, NursingLevelVo.class);
        return nursingLevelVoPageResponse;
    }

    @Override
    public NursingLevelVo queryById(Long id) {
        NursingLevel nursingLevel=nursingLevelMapper.queryById(id);
        System.out.println("***********************************************");
        System.out.println(nursingLevel);
        NursingLevelVo bean = BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
        System.out.println("***********************************************");
        System.out.println(bean);
        return bean;
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void delete(Long id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public void statusChange(Long id, Integer status) {
        nursingLevelMapper.statusChange(id,status);
    }
}
